<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.model.PostCheck"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="com.shsh.safemanage.model.Department1PostcheckMapping"%>
<%@page import="com.shsh.safemanage.dao.PostCheckDao"%>
<%@page import="com.shsh.safemanage.dao.DepartmentDao"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%
{
	Long postcheckID=0l;
	Integer year = 0;
	Integer month = 0;
	
	try{
		postcheckID = Long.parseLong(request.getParameter(Constants.REQUEST_PARAMETER_POSTCHECK_ID));
	} catch (Exception e){
		
	}
	
	PostCheckDao postcheckDao = DaoCreator.createPostCheckDao();
	PostCheck postcheck = postcheckDao.getPostCheck(postcheckID);
	
	
	try{
		year = Integer.parseInt(request.getParameter(Constants.REQUEST_PARAMETER_YEAR));
	}catch(Exception e){
		
	}
	
	
	try{
		month = Integer.parseInt(request.getParameter(Constants.REQUEST_PARAMETER_MONTH));
	}catch(Exception e){
		
	}
	
	int monthEnd = Util.getMonthEnd(year, month);
	
	DepartmentDao departmentDao = DaoCreator.createDepartmentDao();
	List<Department1> depart1Lst = departmentDao.getDepartment1List(Constants.DEPARTMENT_TYPE_SHIYEBU);
	depart1Lst.addAll(departmentDao.getDepartment1List(Constants.DEPARTMENT_TYPE_JIGUAN));
	
	List<Department1PostcheckMapping> mappingList = postcheckDao.searchDepartment1PostcheckMapping(null, postcheckID);

	List<Long> depart1IDs = new ArrayList<Long>();
	for (Department1PostcheckMapping mapping : mappingList) {
		depart1IDs.add(mapping.getDepart1ID());
	}

	for (Iterator<Department1> iter = depart1Lst.iterator(); iter.hasNext();) {
		Department1 d1 = iter.next();
		if (d1 != null && !depart1IDs.contains(d1.getId())) {
			iter.remove();
		}
	}
%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt;<%=postcheck.getCheckName() %>岗检 &gt;&gt;<%=postcheck.getCheckName() %>岗检记录月表/周表一览
</div>
<div class="tt"><%=postcheck.getCheckName() %>岗检记录月表/周表一览</div>
<div class="content">
	<div>
	<span id="monthSelectSpan" style="margin-left: 10px;float:left;">
	<%@include file="/postcheck_select/month_select_section.jsp" %>
	</span>
		<input type="button" id="btnBack" onclick="goBack()" style="float:right;margin-right: 10px" value="返回"></input>
	</div>
	<table border="1" width="98%" style="align:center;">
	<%
	for (Department1 depart1:depart1Lst) {
	%>
	<tr>
		<td class="td3">
			<%=depart1.getDepartmentName() %>
		</td>
		<td style="font-weight:bold;">
		<a href="javascript:" onclick="openDailyReport(<%=depart1.getId()%>, 1, 7)">第一周</a>
		</td>
		<td style="font-weight:bold;">
		<a href="javascript:" onclick="openDailyReport(<%=depart1.getId()%>, 8, 15)">第二周</a>
		</td>
		<td style="font-weight:bold;">
		<a href="javascript:" onclick="openDailyReport(<%=depart1.getId()%>, 16, 23)">第三周</a>
		</td>
		<td style="font-weight:bold;">
		<a href="javascript:" onclick="openDailyReport(<%=depart1.getId()%>, 24, <%=monthEnd%>)">第四周</a>
		</td>
		<td style="font-weight:bold;">
		<a href="javascript:" onclick="openDailyReport(<%=depart1.getId()%>, 1, <%=monthEnd%>)">月表</a>
		</td>
	</tr>
	<%
	}
	%>
	</table>
	<table width="100%" >
		<tr>
		<td style="text-align:center;"  width="100%">
			<input type="button" id="btnBack2" onclick="goBack()" value="返回"></input>
		</td>
		</tr>
	</table>
</div>
<script type="text/javascript">
function goBack(){
	var year = getElementValueByID("year");
	var month = getElementValueByID("month");
	loadPageSection('<%=request.getContextPath()%>/postcheck/report/postcheck_summary_report.jsp', 'mainContentDiv', {postcheckID: <%=postcheck.getId()%>, year: year, month: month}, true);
}

function selectYear() {
	var year = getElementValueByID("year");
	var month = getElementValueByID("month");
	loadPageSection('<%=request.getContextPath()%>/postcheck/report/postcheck_month_report.jsp', 'mainContentDiv', {postcheckID: <%=postcheck.getId() %>, year: year, month: month, display: '0'}, true);
}

function selectMonth() {
	var year = getElementValueByID("year");
	var month = getElementValueByID("month");
	loadPageSection('<%=request.getContextPath()%>/postcheck/report/postcheck_month_report.jsp', 'mainContentDiv', {postcheckID: <%=postcheck.getId() %>, year: year, month: month, display: '0'}, true);
}

function openDailyReport(depart1ID, dayStart, dayEnd) {
	loadPageSection(
			'<%=request.getContextPath()%>/postcheck/report/postcheck_user_daily_report.jsp', 
			'mainContentDiv', 
			{
				fromPage: 'postcheck/report/postcheck_month_report',
				postcheckID: <%=postcheck.getId() %>,
				depart1ID: depart1ID,
				year: <%=year%>, 
				month: <%=month%>,
				dayStart: dayStart,
				dayEnd: dayEnd
			}, 
			true);	
}
</script>
<%
}
%>